package com.kermel.andromeda.data;

import java.util.ArrayList;

import android.content.Context;

import com.kermel.andromeda.R;
import com.kermel.common.util.StringUtils;

public enum WhenCountdownTimerEndsChoice {
    
    UNKNOWN(R.string.unknown),
    PLAY_SOUND(R.string.playSound);
    
    private int localizedDisplayNameResID;
    
    private WhenCountdownTimerEndsChoice(int resID) {
        localizedDisplayNameResID = resID;
    }
    
    public static WhenCountdownTimerEndsChoice[] getAllValuesExceptUnknown() {
        WhenCountdownTimerEndsChoice[] choices = values();
        ArrayList<WhenCountdownTimerEndsChoice> working = new ArrayList<WhenCountdownTimerEndsChoice>();
        
        for (WhenCountdownTimerEndsChoice choice : choices) {
            if (choice.isNotUnknown())
                working.add(choice);
        }
        
        int numItems = working.size();
        WhenCountdownTimerEndsChoice[] allValuesExceptUnknown = new WhenCountdownTimerEndsChoice[numItems]; 
        working.toArray(allValuesExceptUnknown);
        
        return allValuesExceptUnknown;
    }
    
    public static WhenCountdownTimerEndsChoice getChoiceByLocalizedDisplayNameResID(int resID) {
        WhenCountdownTimerEndsChoice[] choices = values();
        
        for (WhenCountdownTimerEndsChoice choice : choices) {
            int choiceResID = choice.getLocalizedDisplayNameResID();
            
            if (choiceResID == resID)
                return choice;
        }
        
        return UNKNOWN;
    }
    
    public static WhenCountdownTimerEndsChoice getChoiceByLocalizedDisplayName(Context context, String displayName) {
        
        if (context != null && StringUtils.isNotBlank(displayName)) {
            WhenCountdownTimerEndsChoice[] choices = values();
            
            for (WhenCountdownTimerEndsChoice choice : choices) {
                int choiceResID = choice.getLocalizedDisplayNameResID();
                
                String choiceDisplayName = context.getString(choiceResID);
                
                if (displayName.equals(choiceDisplayName))
                    return choice;
            }
        }
        
        return UNKNOWN;
    }
    
    public int getLocalizedDisplayNameResID() {
        return localizedDisplayNameResID;
    }
    
    public boolean isUnknown() {
        return this == UNKNOWN;
    }
    
    public boolean isNotUnknown() {
        return this != UNKNOWN;
    }
    
    public boolean isPlaySound() {
        return this == PLAY_SOUND;
    }
    
    public boolean isNotPlaySound() {
        return this != PLAY_SOUND;
    }
    
    
}
